<?php
//  event/Form/EventSearch.php
class event_Form_EventSearch extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild($params)
    {
    	$this->setMethod('POST');
//	    $e = $params['view']->hvnUrl(array('module' => 'event', 'action'=>'search'), 'nocontroller');
//    	$this->setAction($e);
    	
    	$this->setAction($params['action_url']);
		
	    $myValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\-]*$/i'); //alpha, num, space, -, _
        $myValidator->setMessage(t(60), Zend_Validate_Regex::NOT_MATCH);
		$this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');
		
        
        // add the submit button
		$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                           'label' => t(67) ));
        $submit->setAttrib("class", 'search-button');
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);

		//add title
        $title = new Zend_Form_Element_Text('title', 
                         array('disableLoadDefaultDecorators' => true,'size' => '60',
//                               'required'   => true,             
                               'class' => 'keywordInput'));
        
        $title->addDecorators($this->_noDecorator)
        	 ->addValidator($myValidator);
        $this->addElement($title);
        

        //add search time
 		$quick_time_range_mode = new Zend_Form_Element_Select('quick_time_range_mode',  
                         array('disableLoadDefaultDecorators' => true));
        $quick_time_range_mode->addMultiOption(1,__('Next 7 days'))
                               	->addMultiOption(2,__('Next 30 days '))
                               	->addMultiOption(3,__('Next 3 months'))
                           	->addDecorators($this->_noDecorator);
        $quick_time_range_mode->setValue(2);
        $this->addElement($quick_time_range_mode);
        
        //City
        $city_id = new Zend_Form_Element_Select('city_id',array('disableLoadDefaultDecorators' => true,
                                                             'required' => true));
        $city_id->addMultiOption('0','--'.t(717).'--');
        $table = new place_Model_City();
        $topCities = Zend_Registry::get('configuration')->topCities->toArray();
        $city_id->addMultiOptions($topCities)
		        ->setAttrib('disable', array('1a'));
        foreach ($table->fetchAll() as $c) {
            $city_id->addMultiOption($c->city_id, $c->city_name);
        $city_id->addDecorators($this->_noDecorator);
        }
        $this->addElement($city_id);

        //add category
        if($params['cluSearchMode'] == 'simpleSearch')
        	$category = new Zend_Form_Element_Select('category',  
                         array('disableLoadDefaultDecorators' => true
                         ));
        else                 
        	 $category = new Zend_Form_Element_MultiCheckbox('category',  
                         array('disableLoadDefaultDecorators' => true
                         ));
                                          
    	$mCategory = new category_Model_Category();
        $mCategory->setTables('event');
        foreach($mCategory->getRootType('Root_Event') as $e) {
            $category->addMultiOption($e['id'], p($e['name']));
        }             
        $category->addDecorators($this->_noDecorator);
        $this->addElement($category);
        
        //add start date
        $startDate= new Zend_Form_Element_Text('startDate',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
        $startDate->addDecorators($this->_noDecorator)
//                  ->addFilter($dateValidator)
                  ;
        $startDate->size = 10;
        //$startDate->setValue(date("d/m/Y",time()));
        $this->addElement($startDate);
        
        //add description
        $description = new Zend_Form_Element_Text('description',
                            array('disableLoadDefaultDecorators' => true,
                    //                                'required' => true
                            'class' => 'inputText'));
        
        $description->addDecorators($this->_noDecorator)
        	 		->addValidator($myValidator);
        $this->addElement($description);
        
        //add finish date
        $finishDate = new Zend_Form_Element_Text('finishDate',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
        $finishDate->size = 10;
        $finishDate->addDecorators($this->_noDecorator)
//                  ->addFilter($dateValidator)
                  ;
        //$finishDate->setValue(date("d/m/Y",time() + 2592000));
        $this->addElement($finishDate);
        
        
        if($params['cluSearchMode'] == 'simpleSearch')
			return;

		//-----------------------------------fullSearch ----------------------------               
        //District
       $district_id = new Zend_Form_Element_Select('district_id',array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $district_id->addMultiOption('0','--'.t(718).'--')
                    ->setRegisterInArrayValidator(false)	
                    ->addDecorators($this->_noDecorator);
 
        $this->addElement($district_id);
        
		
		//add keywords
        $keywords = new Zend_Form_Element_Text('keywords', 
                         array('disableLoadDefaultDecorators' => true,
//                             'required'   => true,             
                               'class' => 'inputText'));
        $keywords->addDecorators($this->_noDecorator)
        	 	->addValidator($myValidator);
        $this->addElement($keywords);
			
         //add events per page
 		$events_per_page = new Zend_Form_Element_Select('events_per_page',  
                         array('disableLoadDefaultDecorators' => true));
   	 	$events_per_page->addMultiOption(10,t(62))
               				->addMultiOption(20,t(63))
                           	->addMultiOption(30,t(64))
                           	->addMultiOption(40,t(65))
                           	->addMultiOption(50,t(66))
                           	->addDecorators($this->_noDecorator);
        $this->addElement($events_per_page);

        
		//add frequency
        $frequency = new Zend_Form_Element_Select('frequency',  
                         array('disableLoadDefaultDecorators' => true
//                                'required' => true
                         )); 
        $frequency->addMultiOption('all'   ,t(61))
        		  ->addMultiOption('once'   ,t(44))
            	  ->addMultiOption('daily'  ,t(45))
                  ->addMultiOption('weekly' ,t(46))
                  ->addMultiOption('monthly',t(47))
                  ->addMultiOption('yearly' ,t(48))
                  ->addDecorators($this->_noDecorator);
        $this->addElement($frequency);
        
        //add calendarType
        $calendarType = new Zend_Form_Element_Select('calendarType',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
        $calendarType->addMultiOption('solar',t(49))
                 ->addMultiOption('lunar'   ,t(50))
                 ->addDecorators($this->_noDecorator);
        $this->addElement($calendarType);
        
        //add from day
        $fromDay = new Zend_Form_Element_Select('fromDay',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
         
        $fromDay->addMultiOption(2,t(51))
        	   ->addMultiOption(3,t(52))
               ->addMultiOption(4,t(53))
               ->addMultiOption(5,t(54))
               ->addMultiOption(6,t(55))
               ->addMultiOption(7,t(56))
               ->addMultiOption(8,t(57))
    		   ->addDecorators($this->_noDecorator)
//             ->addFilter($dateValidator)
                  ;
        $this->addElement($fromDay);

        //add to day
        $toDay = new Zend_Form_Element_Select('toDay',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
         
        $toDay->addMultiOption(2,t(51))
        	   ->addMultiOption(3,t(52))
               ->addMultiOption(4,t(53))
               ->addMultiOption(5,t(54))
               ->addMultiOption(6,t(55))
               ->addMultiOption(7,t(56))
               ->addMultiOption(8,t(57))
        		   ->addDecorators($this->_noDecorator)
//                  ->addFilter($dateValidator)
                  ;
        $this->addElement($toDay);
        
         if($params['cluSearchMode'] == 'fullSearch')
			return;
        //----------------------------------fullAdminSearch-------------------------------
        //status
        $status = new Zend_Form_Element_Select('status',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
        $status->addMultiOption('all','--'.t(61).'--')
        	   ->addMultiOption('featured ',t(33))
        	   ->addMultiOption('published',t(34))
               ->addMultiOption('queued',t(35))
               ->addMultiOption('unpublished',t(36))
               ->addMultiOption('deleted',t(37))
               ->addDecorators($this->_noDecorator);

        $this->addElement($status);
        
        //userId
        $userId = new Zend_Form_Element_Text('poster_id', array('disableLoadDefaultDecorators' => true,
                                                         'class' => 'inputText',
                                                         'required' => false));
        $userId->addDecorators($this->_noDecorator);
        $this->addElement($userId);
        
    }
    
    public function populateDataSearch($data)
    {
    	if(isset($data['start_date']))
    		$data['startDate'] = $data['start_date'];
    	if(isset($data['finish_date']))
    		$data['finishDate'] = $data['finish_date'];
    	$this->populate($data);
    }
}
?>
